<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
	
<div class="modal fade" id="add_warehouse_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 600px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<div class="page_header"><a>新增仓库</a></div>
			</div>
			<form id="add_warehouse_form" enctype="multipart">
				<input type="hidden" name="firstid" id="firstid">
				<div class="box modal-body">
					<p>
							<label class="must">仓库代码</label>
							<input type="text" readonly placeholder="自动生成" class="form-control"></input>
							<label class="must">仓库名称</label>
							<input type="text" name="warehousename" class="form-control"></input>
					</p>
					<p>
							<label class="must">联系方式</label>
							<input type="text" name="telephone" class="form-control"></input>
							<label class="must">状态</label>
							<select name="status" class="form-control select">
								<option value="可用">可用</option>
								<option value="不可用">不可用</option>
							</select>
					</p>
					<p>
							<label class="must">地址</label>
							<input type="text"  name="address" class="form-control"></input>
					</p>
					<p>
							<label class="must">备注</label>
							<input type="text"  name="remarks" class="form-control"></input>
					</p>
				</div>
			</form>
			<div class="red" id="add_warehouse_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button"  onclick="saveAddWarehouse();" class="btn btn1">保存</button>
				<button type="button"  data-dismiss="modal" class="btn btn1">取消</button>
			</div>
		</div>
	</div>
</div>
<script>

function addWarehouse(){
	$('#add_warehouse_info :text').val("");
	$("#add_warehouse_info select").val("");
	$('#add_warehouse_info').modal('show');
}

function saveAddWarehouse(){
	if(!validateAddFormtwo()) return ;//校验
	
    var formData = $("#add_warehouse_form").serialize();  
	$.ajax({
		url:"<%=basePath %>warehouse/add.do",
		type:"post",
		async : false,
		dataType:"json",
		data : formData,
		success:function(data){
			if(data.result=="success"){
				$("#add_warehouse_msg").html("");
				$('#add_warehouse_info :text').val("");
				$("#add_warehouse_info select").val("");
				$('#add_warehouse_info').modal('hide');
				location.href=location.href;
			}else{
				$("#add_warehouse_msg").html("新增仓库失败：",data.error);
			}
		},
		error :function(){
			$("#add_warehouse_msg").html("新增仓库失败！")
		}
	});
}


//仓库管理校验
function validateAddFormtwo(){

 	if(!validateString("仓库名称","#add_warehouse_form [name='warehousename']",30,false)){
		return false;
	}  
	
	if(!validateRegex("联系方式","#add_warehouse_form [name='telephone']",/^1[0-9]{10}$/,false)){
		return false;
	}
	
	 if(!validateSelect("状态","#add_warehouse_form [name='status']",120,false)){
		return false;
	}
	
	if(!validateString("地址","#add_warehouse_form [name='address']",120,false)){
		return false;
	}
	
	if(!validateString("备注","#add_warehouse_form [name='remarks']",190,false)){
		return false;
	} 
	return true;
}


</script>